import Mock from 'mockjs'

const List = []
const count = 100

const baseContent = '<p>I am testing data, I am testing data. </p><p><img src="https://wpimg.wallstcn.com/4c69009c-0fd4-4153-b112-6cb53d1cf943"></p>'

for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id: '@increment',
    messageType: 3,
    conversation_id: 3,
    contentAttributes: {},
    contentType: 'inputEmail',
    createdAt: +Mock.Random.date('T'),
    content: baseContent
  }))
}

export default [
  {
    url: '/api/v1/messages',
    type: 'get',
    response: config => {
      console.log(config)
      const { importance, type, title, page = 1, limit = 20, sort } = config.query

      let mockList = List.filter(item => {
        if (importance && item.importance !== +importance) return false
        if (type && item.type !== type) return false
        if (title && item.title.indexOf(title) < 0) return false
        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }

      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

      return pageList
    }
  },
  {
    url: '/api/v1/messages',
    type: 'post',
    response: config => {
      console.log(config)
      return {
        id: 7,
        content: 1,
        inbox_id: 1,
        conversation_id: 2,
        phoneNumber: 0,
        created_at: 1615545463,
        private: false,
        source_id: null,
        sender: {
          additionalAttributes: null,
          email: '1@1.com',
          id: 3,
          identifier: null,
          name: 1,
          phoneNumber: null,
          pubsub_token: 'PRn773QnFD4tEaaSabkXd2xA',
          thumbnail: '',
          type: 'contact'
        }
      }
    }
  },
  {
    url: '/api/v1/file-messages',
    type: 'post',
    response: config => {
      console.log(config)
      return {
        id: 8,
        content: null,
        inbox_id: 1,
        conversation_id: 2,
        messageType: 0,
        created_at: 1615546548,
        private: false,
        source_id: null,
        attachments: [
          {
            id: 1,
            messageId: 8,
            file_type: 'file',
            account_id: 1,
            extension: null,
            data_url: 'http://localhost:9537/9a5e2ace-33f1-40d0-854e-deb96acdf24d',
            thumb_url: ''
          }
        ],
        sender: {
          additionalAttributes: null,
          email: '1@1.com',
          id: 3,
          identifier: null,
          name: 1,
          phone_number: null,
          pubsub_token: 'PRn773QnFD4tEaaSabkXd2xA',
          thumbnail: '',
          type: 'contact'
        }
      }
    }
  }
]

